//
//  TGMModel2CollectionViewAdapter.h
//  TravelGuideHD
//
//  Created by xiaofeng on 14-9-2.
//  Copyright (c) 2014年 mafengo Inc. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "TGMModel2ScrollViewAdapter.h"
#import "TGMCollectionViewEmptyCell.h"
#import "TGMCollectionViewMoreCell.h"

@class TGMModel2CollectionViewAdapter;
@protocol TGMModel2CollectionViewDelegate <TGMModel2ScrollViewAdapterDelegate>

@optional

- (BOOL)adapter:(TGMModel2CollectionViewAdapter*)adapter collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath;

- (UIEdgeInsets)adapter:(TGMModel2CollectionViewAdapter*)adapter scrollContentInset:(UICollectionView*)collectionView;

@end

@protocol TGMModel2CollectionViewDelegateFlowLayout <NSObject>
@optional
- (CGSize)model2CollectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;
- (UIEdgeInsets)model2CollectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section;
- (CGFloat)model2CollectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section;
- (CGFloat)model2CollectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section;
- (CGSize)model2CollectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section;
- (CGSize)model2CollectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section;

- (void)model2CollectionView:(UICollectionView*)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath;
@end


@interface TGMModel2CollectionViewAdapter : TGMModel2ScrollViewAdapter<TGMModel2CollectionViewDelegateFlowLayout, TGMCollectionViewMoreCellDelegate>
{
    @protected
    TGMCollectionViewMoreCell *_getMoreCell;
    TGMCollectionViewEmptyCell *_emptyCell;
    
    id _listData;
    BOOL _hasBinded;
}
@property(nonatomic, weak, readonly)UICollectionView *collectionView;
@property(nonatomic, strong, readonly)TGMBaseModel *model;

@property(nonatomic, weak)id<TGMModel2CollectionViewDelegate> delegate;

@property(nonatomic, strong)id listData;
@property(nonatomic, readonly)BOOL hasBinded;

@property(nonatomic, strong)UIImage *emptyContentImage;//内容为空时候的图片，子类可以覆盖getter方法
@property(nonatomic, strong)NSString *emptyContentText;//内容为空时候的文字
/**
 *  当前tableview的contentOffset。当刷新还没有完成的时候，返回初始UNKNOWN
 *
 *  @return contentOffset
 */
- (int)markedContentOffsetYOfTableView;

/**
 * @param collectionView
 * @param model
 * @param initOffsetY
 */
- (void)bindCollectionView:(UICollectionView*)collectionView
                 withModel:(TGMBaseModel*)model
                actionData:(TGMBaseModelActionData*)actionData
                 atOffsetY:(int)initOffsetY;

- (void)bindCollectionView:(UICollectionView*)collectionView
                 withModel:(TGMBaseModel*)model
                actionData:(TGMBaseModelActionData*)actionData
                 atOffsetY:(int)initOffsetY
                emptyImage:(UIImage*)emptyImage
                 emptyText:(NSString*)emptyText;

- (BOOL)shouldModelInitRefresh;//default return YES

/**
 *  You could register reuseable cell in this function
 *
 *  @param collectionView
 */
- (void)registerCollectionViewCells:(UICollectionView*)collectionView;

// 此函数里设置内容为空的时候的cell样式，一般都是修改空的时候的图片
- (void)willShowEmptyContentCell;

@end

@interface TGMModel2CollectionViewAdapter(Private)
#pragma mark - Model2UIDataSource

- (NSInteger)model2CollectionNumberOfSectionsInCollectionView:(UICollectionView *)collectionView;

- (UICollectionReusableView *)model2CollectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;

- (NSInteger)model2CollectionView:(UICollectionView*)collectionView numberOfItemsInSection:(NSInteger)section;

- (UICollectionViewCell *)model2CollectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;
@end
